package com.mxnet.chongjin.supoman.utils;

import java.util.List;

/**
 * author:chongjin
 * email:lcj270018655@163.com
 * date:2018/7/10
 * other:
 */

public class ByteArrayUtils {
    public static byte[] MergeByteArray (List<byte[]> byteList) {
        int length = 0;
        for (byte[] b:byteList) {
            length += b.length;
        }
        byte[] result = new byte[length];
        int destPosition = 0;
        for (byte[] bytes:byteList) {
            System.arraycopy(bytes, 0, result, destPosition, bytes.length);
            destPosition += bytes.length;
        }
        return result;
    }

    public static byte[] ipToHex(String ip)
    {
        String arr[]=ip.split("\\.");
        if(arr.length==4)
        {
            byte[] rv=new byte[4];
            String hex="";
            for(int i=0;i<4;i++)
            {
                String p=arr[i];
                rv[i]= (byte)(Integer.parseInt(p) & 0xff);
            }
            //rv =StringUtils.hexStr2Bytes( hex) ;
            return rv;

        }
        else
            return null;

    }
}
